/*
    Copyright 2010 Nathaniel Fairfield <than@timbrel.org>

    This file is part of Ravec.

    Ravec is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Ravec is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Ravec.  If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef _RAVEC_TEST_UTILS_H_
#define _RAVEC_TEST_UTILS_H_

#include <stdio.h>
#include <sys/time.h>
#include <assert.h>

// TODO: convert these to templatized functions?

#define RUN_TEST(x) { \
  fprintf(stderr, "Running " #x " ...\n"); \
  x(); \
  fprintf(stderr, " Done\n"); \
}

// NOTE: gettimeofday is REAL time, not just PROCESS time.
#define RUN_BENCHMARK(x, i) { \
  fprintf(stderr, "Running " #x " %d iterations ...\n", i); \
  struct timeval tp; \
  gettimeofday(&tp, NULL); \
  double before = tp.tv_sec + tp.tv_usec / 1e6; \
  x(i); \
  gettimeofday(&tp, NULL); \
  double after = tp.tv_sec + tp.tv_usec / 1e6; \
  fprintf(stderr, " Total: %lf seconds\n", after - before); \
  fprintf(stderr, " Per iteration: %g seconds\n", (after - before) / i); \
}

#define CHECK(x) assert(x)

#endif  // _RAVEC_TEST_UTILS_H_
